package com.share.entity;

import lombok.Data;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import sun.reflect.ReflectionFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

public class Item {

    private HashMap<String,String> hm = new HashMap<>();
    private List<String> list = new ArrayList<>();
    private List<Dog> dogs = new ArrayList<>();

    public static void main(String[] args){
//        test1();
//        test2();
//        test3();
//        test4();
//        test5();
        //test6();
        Dog dog = new Dog();
        dog.setAge(1);
        dog.setName("sunxj");


    }

    private static void test6() {
        //ReflectionToStringBuilder – 使用反射机制辅助实现Object.toString()方法；
        String sunxj = ReflectionToStringBuilder.toString(new Dog("sunxj", 26));
        System.out.println(sunxj);
    }

    private static void test5() {
        System.out.println(Objects.equals(new Dog(), new Dog()));
    }

    private static void test4() {
        List<Dog> list1 = new ArrayList<>();
        List<Dog> list2 = new ArrayList<>();
        System.out.println(list1.equals(list2));
        list1.add(new Dog());
        list2.add(new Dog());
        System.out.println(list1.equals(list2));
    }

    private static void test3() {
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        System.out.println(list1.equals(list2));
        list1.add("1");
        list2.add("1");
        System.out.println(list1.equals(list2));
    }

    private static void test2() {
        Item item1 = new Item();
//        item1.hm.put("1","1");
        item1.list.add("1");
        Item item2 = new Item();
        item2.list.add("1");
        System.out.println("item1:"+item1.hashCode());
        System.out.println("item2:"+item2.hashCode());
        boolean res = item1.equals(item2);
        System.out.println(res);
    }

    private static void test1() {
        Item item = new Item();
        item.hm.put("1","1");
        item.list.add("1");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Item)) return false;
        Item item = (Item) o;
        System.out.println(hm);
        System.out.println(item.hm);
        System.out.println(list);
        System.out.println(item.list);
        return Objects.equals(hm, item.hm) &&
                Objects.equals(list, item.list);
    }

    @Override
    public int hashCode() {
        return Objects.hash(hm, list);
    }
}

@Data
class Dog {
    private String name;
    private int age;

    public Dog() {};

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }
}